
#ifndef TIMESTAMP_HPP
#define TIMESTAMP_HPP
// C++ STl
#include <string>

// C API
#include <stdint.h>

namespace tulun
{
    class Timestamp
    {
    private:
        uint64_t micr_; // 微秒

    public:
        Timestamp();
        Timestamp(uint64_t ms);
        ~Timestamp();
        void swap(Timestamp &other);
        std::string toString() const;
        // "1234567.3456Z";
        std::string toFormattedString(bool showmicro = true) const;
        // "2025/6/10 10:56:12"
        // "2025/6/10 10:56:12.4567Z"
        std::string toFormattedFile() const;
        // 20250610105612.4567
        bool valid() const;
        uint64_t getmicro() const;
        uint64_t getsecond() const;
        const Timestamp &now();
        operator uint64_t() const;

    public:
        static Timestamp Now();
        static Timestamp Invalid();
        static const uint32_t kMicPerSec = 1000 * 1000;
    };
    inline time_t diffSecond(const Timestamp &a, const Timestamp &b)
    {
        return a.getsecond() - b.getsecond();
    }
    inline time_t diffMicro(const Timestamp &a, const Timestamp &b)
    {
        return a.getmicro() - b.getmicro();
    }
    inline Timestamp addMicro(const Timestamp &te, double micro)
    {
        Timestamp temp(te.getmicro() + micro);
        return temp;
    }
    inline Timestamp addSecond(const Timestamp &te, double sec)
    {
        Timestamp temp(te.getmicro() + sec * Timestamp::kMicPerSec);
        return temp;
    }
} // namespace tulun

#endif